var currentPage = 1;
var sortTypeId = "";
var propertyTypeId = "";
var allSort = "";
var addTimeSort = "";
var gPriceSort = "";
var dPriceSort = "";
var collectNumSort = "";
var saleNumSort = "";
var fenleiId = "";
var shuxinId = "";
var priceId = "";
var shangquanid = "";
fenlei();

function qiugoujia() {
	if(uuuuid != "") {
		window.location.href = "4.5.2weihuo_fabu.html";
	} else {
		alert("未登录/或登录超时");
		window.location.href = "buy/12.0.0buy_wode.html";
	}
}

function fenlei() {
	$("#sortUl").html("");

	$.ajax({
		url: urlcore + "/api/sortType/Primaryclassification?coder=2",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			var suns = 0;
			var sortUl = "";
			$.each(data.data.sortTypeList, function(i, n) {
				suns++;
				if(suns == 1) {
					sortUl += '<li><a href="javascript:TwoclassificationFenlei2();">全部分类</a></li>';
				}
				sortUl += '<li><a href="javascript:TwoclassificationFenlei(' + n.id + ');">' + n.sortName + '</a></li>';
			});
			$("#sortUl").append(sortUl);
		},
		error: function() {
			/* Act on the event*/ //商品类别已完结
			alert("error");
		}
	});
}

function TwoclassificationFenlei2() {
	$("#area span").text("全部分类");
	fenleiId = "";
	$('#qiugou').html("");
	currentPage = 1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}

function TwoclassificationFenlei(str) {
	$("#sortSon").html("");
	$.ajax({
		url: urlcore + "/api/sortType/TwoGoodsAlls?id=" + str,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.data != null) {
				$.each(data.data, function(g, h) {
					var Fenleierji = '<li id="' + h.id + '"><a href="javascript:selectChanPinByfenlei(' + h.id + ',\'' + h.sortName + '\');">' + h.sortName + '</a></li>';
					$("#sortSon").append(Fenleierji);
				});
			}
		},
		error: function() {
			 //商品类别已完结
			alert("error");
		}
	});
}

function selectChanPinByfenlei(id, name) {
	$("#area span").text(name);
	fenleiId = id;
	$('#qiugou').html("");
	currentPage = 1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}

function selectChanPinByprice(id, name) {
	$("#price span").text(name);
	priceId = id;
	$('#qiugou').html("");
	currentPage = 1;
	selectRemai();
	$(".retrie dt a").removeClass('up');
	$('.downlist').hide();
}

selectRemai();
var ss = 0;

function selectRemai() {
	if(currentPage == 1 || currentPage == 2 || ss != 0) {
		$.ajax({
			url: urlcore + "/api/poop/selectPoopList?current=" + currentPage + "&goodsType=5&sortTypeId=" + fenleiId + "&sort=" + priceId + "&tradeAreaId=" + shangquanid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
					ss = data.data.list.length;
					$.each(data.data.list, function(y, n) {
						if(n.goods.total >= 1) {
							var shangping = '<li>' +
								'			<a href="7.0.0goods_detail.html?id=' + n.goodsId + '">' +
								'				<img onerror="errorImg(this)" src="' + n.goods.coverUrl + '" />' +
								'				<h5>&yen;' + n.newPackPrice + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
								'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
								'剩余' + n.goods.total + '件</h5>' +
								'			</a>' +
								'		</li>';
							$("#qiugou").append(shangping);
						}
					});

				}
			},
			error: function() {
				alert("error");
			}
		});
	}
}

//商圈
function shangquan() {
	$.ajax({
		url: urlcore + "/api/tradeArea/selectList",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var suns = 0;
				var shangquan = "";
				$.each(data.data, function(y, n) {
					suns++;
					if(suns == 1) {
						shangquan += '<li  onclick="selsetshangquan2()">全部商圈</li> ';

					}
					shangquan += '<li  onclick="selsetshangquan(' + n.id + ',\'' + n.areaName + '\')">' + n.areaName + '</li> ';

				});
				$("#shangquan").append(shangquan);
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				alert(thisUrl);
				if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				if(data.msg != '空数据') {
					alert(data.msg)
				} else {
					$('#thiscount').text(0);
				}
			}
		},
		error: function() {
			alert("error");
		}
	});
}

function selsetshangquan(id, name) {
	$("#shangquanmingzi").html("");
	$("#shangquanmingzi").html(name);
	shangquanid = id;

	$('#shangquan').hide();
	currentPage = 1;
	$('#qiugou').html("");
	selectRemai();

}